package Chapter02;

/**
 * @author oldliu
 * @since 1.0
 */
public class JClass {
    String name;//名称
    String dirTeacher;
    String techTeacher;
    String startTime;
    //学生信息
    String stus[] = new String[30];

    int pos = 0;//当前人数

    //加新生
    public void add(String stuName) {
        if (pos >= stus.length)
            System.out.println("人已经满了，去下一个班！");
        else {
            stus[pos++] = stuName;
            //stus[pos]=stuName;
            // pos++;
        }
    }

    //显示班级的信息
    public void printInfor() {
        System.out.println("班级名称：" + name + ",指导老师：" + dirTeacher + "和" + techTeacher);
        System.out.println("开班于" + startTime);
        System.out.println("学生信息如下：");
        for (String s : stus) {
            if (s == null)
                break;
            System.out.print(s + " ");
        }
        System.out.println();
    }

    //查找某个学生在不在这个班级
    public boolean search(String sname) {
        for (int i = 0; i < pos; i++) {
            if (stus[i].equals(sname)) {
                return true;
            }
        }
        return false;
    }

    //查找学生位置
    public String find(int index) {
        for (int i = 0; i < stus.length; i++) {
            if (stus[index].equals(stus[i])) {
                System.out.println(stus[i]);
            }
        }
        return stus[index];
    }

    //修改学生信息
    public boolean modify(String oldName, String newName) {
        for (int i = 0; i < stus.length; i++) {
            if (stus[i].equals(oldName)) {
                stus[i]=newName;
                return true;
            }
        }
        return false;
    }

    public boolean standard(int start, int end, String name) {
        // 指定区间数组中，查找姓名
        for (int i = start - 1; i < end; i++) {
            if (stus[i] == null) {
                break;
            }
            if (stus[i].equals(name)) {
                return true;
            }
        }
        return false;
    }
}